
from abc import ABC, abstractmethod

"""
    windows-path: C:\\Project\\FileCube\\filecube-engine\\src\\lib\\pathEngine
    https://learn.microsoft.com/zh-cn/dotnet/standard/io/file-path-formats

    路径属性：
        目录分隔符：
            目录分隔符用于分隔路径中的各个层级。
        绝对路径或相对路径：
            不一定不以 / 开头的就是是相对路径
            如 C:Projects\\apilibrary\\apilibrary.sln 代表 C 驱动器下当前目录下的相对路径
        字符限制：
            路径名或文件名的字符长度限制规则以及字符限制规则
        驱动器分隔符以及驱动器名称规则
"""
class Path(ABC):
    def __init__(self, path: str):
        self.path = path
        self.pathSeperator = '/'
        # self.path_list = self.calc_path_list()
        # self.path_list = self.path.split(self.pathSeparator)

    @staticmethod
    @abstractmethod
    def CheckParameterLegal(path: str) -> bool:
        # 检查路径参数是否合法
        pass

    @abstractmethod
    def check_relative(self) -> bool:
        # 检查路径是否是相对路径
        pass

    @abstractmethod
    def calc_path_list(self) -> list:
        # 计算路径列表, 注意不一定是直接调用 split 方法
        # 比如 windows 下路径首先以 卷驱动器开头
        pass

    @abstractmethod
    def get_parent_path(self) -> 'Path':
        # 获取父路径
        pass

    @abstractmethod
    def get_path(self) -> str:
        # 获取路径字符串
        pass

    # 绝对路径方法
    def check_contained(self, path_to_check: 'Path'):
        """检验以本路径为根节点的文件树中是否包含目标路径"""
        assert self.check_relative() == False and path_to_check.check_relative() == False, 'The two paths must be absolute paths.'
        assert self.separator == path_to_check.separator, 'The seperator of the two paths must be the same.'
        if len(self.path_list) >= len(path_to_check.path_list):
            return False
        else:
            assert len(self.path_list) > 0 and len(path_to_check.path_list) > 0, 'The path must not be empty.'
            for index in range(len(self.path_list)):
                if self.path_list[index] == path_to_check.path_list[index]:
                    continue
                return False
            return True

    def check_equal(self, path_to_check: 'Path'):
        """检验两个路径是否相等"""
        return self.path == path_to_check.path

    # def getPath(self):
    #     return self.path

    # def getSeperatedPath(self):
    #     return self.path_list
    
    # def getParentPath(self):
    #     """获取本路径的父路径"""
    #     assert len(self.path_list) > 0, 'The path must not be empty.'
    #     if len(self.path_list) == 1:
    #         return None # 根路径没有父路径
    #     return Path(self.separator.join(self.path_list[:-1]), self.separator)

    # def change_seperator(self, new_separator: SupportedSeperator):
    #     self.separator = new_separator
    #     self.path = new_separator.value.join(self.path_list)

    # def check_contained(self, path_to_check: 'Path'):
    #     """检验以本路径为根节点的文件树中是否包含目标路径"""
    #     assert self.separator == path_to_check.separator, 'The seperator of the two paths must be the same.'
    #     if len(self.path_list) >= len(path_to_check.path_list):
    #         return False
    #     else:
    #         assert len(self.path_list) > 0 and len(path_to_check.path_list) > 0, 'The path must not be empty.'
    #         for index in range(len(self.path_list)):
    #             if self.path_list[index] == path_to_check.path_list[index]:
    #                 continue
    #             return False
    #         return True
        
    # def check_equal(self, path_to_check: 'Path'):
    #     """检验两个路径是否相等"""
    #     return self.path == path_to_check.path
        